﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="true" CodeBehind="ProductCategory_Manage.aspx.cs" Inherits="TimKen.Web.Admin.ProductCategory.ProductCategory_Manage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentLinkAction" runat="server">
    <span class="action-span"><a href="ProductCategory_Add.aspx">
        <%=GetLangString("AddProductCategory")%></a></span>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentTitle" runat="server">
    <%=GetLangString("MenuProductCategory")%>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentMain" runat="server">
    <%--<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.core.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.mouse.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.position.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.accordion.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.autocomplete.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.button.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.datepicker.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.dialog.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.draggable.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.droppable.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.progressbar.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.resizable.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.selectable.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.slider.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.sortable.js"></script>
	<script type="text/javascript" src="../../Common/Script/jqueryui-1.90/ui/jquery.ui.tabs.js"></script>--%>
    <script type="text/javascript">
//        $(function () {
//            $('#dialog').dialog({
//                modal: true,
//                autoOpen: false,
//                width: 950,
//                buttons: {
//                    "Ok": function () {
//                        $(this).dialog("close");
//                    },
//                    "Cancel": function () {
//                        $(this).dialog("close");
//                    }
//                }
//            });
//        });

        $(document).ready(function () {

            $('#tt').treegrid({
                url: 'ProductCategory_Test.aspx?rnd=' + Math.random(),
                idField: 'CategoryID',
                treeField: 'CategoryName',
                columns: [[
                        { title: 'Task Name', field: 'CategoryName', width: 260 },
                        { field: 'CategoryID', title: 'Manager', width: 540, align: 'right', formatter: Config }
                    ]]
            });
        });

        function Config(value) {
            var obj = $('#tt').treegrid("find", value);
            var _val = "";
            if (value) {
                if (value > 0) {
                    _val = _val + EditConfig(value);
                    _val = _val + " | " + SortConfigTop(value, obj.SortOrder);
                    _val = _val + " | " + SortConfigDown(value, obj.SortOrder);
                    if (obj.ParentID != "0")
                        _val = _val + " | " + AppConfig(value, obj.IsHotKeys, obj.IsHot);
                    if (obj.Config == "true") 
                        _val = _val + " | " + AddConfig(value);
                    if (obj.state == "open")
                        _val = _val + " | " + DeleteConfig(value);
                }
                else {
                    if (obj.Config) {
                        _val = _val + AddConfig(value);
                    }
                }
            }
            return _val;
        }

        function ClickCell(field, row) {
            alert(field + "," + row);
        }

        function EditConfig(value) {
            return "<a href=\"../ProductCategory/ProductCategory_Add.aspx?categoryId=" + value + "&Act=Edit\" target=\"_blank\">编辑</a>";
        }

        function AddConfig(value) {
            //return "<a href=\"javascript:void(0)\" onclick=\"openWin('" + value + "')\" target=\"_blank\">新增子类</a>";
            return "<a href=\"../ProductCategory/ProductCategory_Add.aspx?categoryId=" + value + "&Act=Add\" target=\"_blank\">新增子级</a>";
        }

        function DeleteConfig(value) {
            return "<a href=\"javascript:void(0)\" onclick=\"Manage('" + value + "','Delete')\" >删除</a>";
        }

        function AppConfig(value, IsHotKeys, Sort) {
            if (IsHotKeys == "0")
                return "<input type=\"checkbox\" onclick=\"Manage('" + value + "','HotKeys', 0)\" /> 设为热门词";
            else {
                if (Sort != "0")
                    return "<input type=\"checkbox\" checked=\"checked\" onclick=\"Manage('" + value + "','HotKeys', 1)\" /> 设为热门词 <a  href=\"javascript:void(0)\" onclick=\"Manage('" + value + "','SortOrder',0)\" >置顶</a>";
                else
                    return "<input type=\"checkbox\" checked=\"checked\" onclick=\"Manage('" + value + "','HotKeys', 1)\" /> 设为热门词 <a  href=\"javascript:void(0)\" onclick=\"Manage('" + value + "','SortOrder',2)\" >取消置顶</a>";
            }
        }

        function SortConfigTop(value, Sort) {
            return "<a href=\"javascript:void(0)\" onclick=\"Manage('" + value + "','SortTop', " + Sort + ")\" >上升</a>";
        }

        function SortConfigDown(value, Sort) {
            return "<a href=\"javascript:void(0)\" onclick=\"Manage('" + value + "','SortDown', " + Sort + ")\" >下降</a>";
        }

        function Manage(val, action, type) {
            if (action == "Delete") {
                if (confirm("你确认要删除吗？")) {
                    Submit(val, action, type);
                }
            }
            else if (action == "App") {
                Submit(val, action, type);
            }
            else {
                Submit(val, action, type);
            }
        }

        function Submit(val, action, type) {
            var obj = $('#tt').treegrid("find", val);
            $.post("ProductCategory_Test.aspx", { "Action": action, "value": val, "type": type },
                function (data) {
                    if (data == "false") {
                        if (action == "HotKeys")
                            alert("热门词不能超过5个，总字符个数不能大于20个!");
                    }
                    else {
                        if (action.indexOf("Sort") >= 0)
                            alert("设置成功!");
                    }
                    $('#tt').treegrid("reload", obj.ParentID);
                }
            );
            }

            function openWin(val) {
                var url = "ProductCategory_Add.aspx?categoryId=" + val + "&Act=Add";
                //$('#dd').window('refresh', 'ProductCategory_Add.aspx?categoryId=" + value + "&Act=Add');
//                $('#dialog').dialog({
//                    modal: true,
////                    open: function () {
////                        $('#dialog_p').load(url);
////                    },
//                    width: 900
                //                });
                alert("1");
                $("#myiFrame").attr("src", url);
                $("#dialog").dialog("open");
                return false;
            }
    </script>
    <div>
        <table id="tt" width="100%" style="height:400px;"></table>
        <%--<div id="dialog">
            <p id="dialog_p"></p>
        </div>--%>

        <%--<div id="dialog" title="Dialog Title">
			<iframe id="myiFrame" scrolling="auto" frameborder="0"  width="950" height="400"></iframe>
		</div>--%>
    </div>
</asp:Content>
